<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2018/3/21
 * Time: 15:37
 */
namespace app\admin\model;
use think\Model;
class Column extends Model{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $insert=[
        'status'=>1,
    ];
    public  function child(){
        return  $this->hasMany('column','column_id')->where(['status'=>1]);
    }
    public  static function getchildlist($list=[]){
        $where['column_id']=0;
        $where['status']=1;
        if(count($list)){
            $where['id']=['in',$list];
        }
        return self::with('child')->where($where)->select();
    }
    /**
     * @param $value
     * @return string
     */
    public  function getColumnIdAttr($value)
    {
        switch ($value) {
            case 0:
                return '顶级栏目';
                break;
            default;
                $info=self::get($value);
                return $info['name'];
                break;
        }
    }
}